<template>
	<view class="content">
		<headNav navTitle="直购机"></headNav>
		<view class="item">
			<button @click="linkUrl('/pages/package/index',1)">背包</button>
			<button @click="linkUrl('/pages/my/claimBenefits')">福利</button>
			<button @click="linkUrl('/pages/my/help')">联系</button>
		</view>
		<view class="item">
			<button @click="linkUrl(`/pages/index/directPurchasePreview?shopId=${shopId}&machineId=${machineId}`)">直购预览（页面中间会有一个展示区域  ）</button><!--  -->
		</view>
		<view class="item">
			<button @click="boxPlay">差价打包￥{{machine.package_price}}<br>转发价￥{{machine.forward_package_price}}</button>
			<button @click="linkUrl(`/pages/index/selfPurchased?shopId=${shopId}&machineId=${machineId}`)">转发价格￥{{machine.forward_price}}<br>立即购买￥{{machine.direct_price}}</button><!-- 直购购买 -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shopId: '',
				machineId: '',
				machine: {},
			};
		},
		onLoad(e) {
			// 移除用户选择的缓存数据
			uni.removeStorageSync('userSelects');
			uni.removeStorageSync('userSelectsIds');
			this.shopId = e.shopId;
			this.machineId = e.machineId;
			this.machinesDetailFn();
			// this.Toggle2() 
		},
		methods:{
			linkUrl(url,type=0){
				if(type==0){
					
				uni.navigateTo({
					url
				})
				}else{
					
				uni.reLaunch({
					url
				})
				}
			},
			// 通过ID获取机台详情
			machinesDetailFn() {
				this.$http('/v1/machines/detail/' + this.machineId).then(res => {
					console.log(res, "获取机台详情");
					if (res.code == 0) {
						const data = res.data;
						this.machine = data.machine;
						// 试一试列表
						this.haveShotList = data.all_images.filter(item => {
							return item.parent_id == 0;
						})
						this.totalWeight = this.haveShotList.reduce((sum, item) => sum + item.weight, 0);
						console.log(this.totalWeight, '总权重', this.haveShotList);
						/* 数组item权重和=总权重
						a权重 1
						b权重 2
						总权重 1 +2 =3
						a 1/3
						b 2/3 */
						// this.shopsDetail = res.data.shop;
						// this.is_followed = res.data.is_followed;
					} else {
						this.$showToast(res.msg)
					}
				})
			
			},
			// 差价打包
			boxPlay() {
				uni.setStorageSync('userSelects', this.machine)
				this.linkUrl(
					`/pages/my/orderConfirmation?price=${this.machine.package_price}&playType=purchasebox&shopId=${this.shopId}&machineId=${this.machineId}`
				)
			},
		}
	}
</script>

<style lang="scss" scoped>
.content{
	@include flexLayout(center,center);
	flex-direction:column;
	min-height: 100vh;
	.item{
	@include flexLayout(center,center);
	}
}
</style>
